"""
@Time ： 2021/10/18 17:15
@Auth ： ChenZhangkun
"""


class HouseItem:
    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return "[%s] 占地 %.2f" % (self.name, self.area)


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        # 剩余面积
        self.freeArea = area
        # 家具名称列表
        self.item_list = []

    def __str__(self):
        return ("户型：%s\n总面积：%.2f[剩余：%.2f]\n家具：%s"
                % (self.house_type, self.area, self.freeArea, self.item_list))

    def add_item(self, item):
        print("要添加 %s" % item)
        # 减去剩余面积
        self.freeArea = self.freeArea - item.area
        # 添加家具
        self.item_list.append(item.name)

    def remove_item(self, item):
        print("要移除 %s" % item)
        self.freeArea += item.area
        self.item_list.remove(item.name)


# 创建家具
bed = HouseItem("席梦思", 4)
chest = HouseItem("衣柜", 2)
table = HouseItem("餐桌", 1.5)
print(bed)
print(chest)
print(table)
# 创建房子
my_home = House("两室一厅", 60)
print(my_home)
my_home.add_item(bed)
my_home.add_item(chest)
my_home.add_item(table)
print(my_home)
my_home.remove_item(table)
print(my_home)
